home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 21 code / Hierarchical Lists / CMyHierListBox.cp < prev    next >
Encoding:
Text File  |  1994-08-27  |  1.6 KB  |  52 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CMyListBox.h            ©1994 Jan Bruyndonckx All rights reserved.
  3. //    v1.0 18/6/94
  4. //
  5. //    A hierarchical demo listbox
  6. //
  7. // ===========================================================================
  8.  
  9. #include <string.h>
  10. #include "CMyHierListBox.h"
  11.  
  12. //----------------------------------------------------------------------------
  13.  
  14. CMyHierListBox* CMyHierListBox::CreateFromStream (LStream *inStream)
  15. {
  16.   return (new CMyHierListBox(inStream));
  17. }
  18.  
  19. CMyHierListBox::CMyHierListBox (LStream *inStream) : CTwistDownListBox (inStream)
  20. { Cell cell = { -1, 0 } ;
  21.  
  22.   ExpandElement (cell) ;
  23. }
  24.  
  25. //----------------------------------------------------------------------------
  26.  
  27. static StringPtr myElements[] = {
  28.     "\pOne", "\pTwo", "\pThree", "\pFour", "\pFive" } ;
  29.  
  30. void CMyHierListBox::ExpandElement (const Cell theCell)
  31. { short            num = sizeof (myElements)/sizeof(StringPtr),
  32.                   i,
  33.                   indent = 0;
  34.   Cell            cell = {0, 0} ;
  35.   Byte            buffer[100] ;
  36.   TwistDownRecPtr    thisTwist = (TwistDownRecPtr) GetCellPtr (theCell) ;
  37.   TwistDownRecPtr    anElement = (TwistDownRecPtr) buffer ;
  38.   
  39.   if (thisTwist)    indent = thisTwist->indent + 1 ;
  40.   
  41.   ::LAddRow (num, theCell.v+1, mMacListH) ;
  42.  
  43.   for (cell.v = theCell.v+1, i = 0 ; i < num ; i++, cell.v++)
  44.       { anElement->indent = indent ;
  45.         anElement->flags = 0x01 ;    // has sublist
  46.         ::memcpy (anElement->data, myElements[i]+1, *myElements[i]) ;
  47.         ::LSetCell (anElement, sizeof (TwistDownRec) - 2 + *myElements[i], cell, mMacListH) ;
  48.       }
  49. }
  50.  
  51. //----------------------------------------------------------------------------
  52.